<!DOCTYPE html>
<html>
    <head>

        <title>Home | VTVNOW</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="format-detection" content="telephone=no">
        <link href="<?php echo $baseurl; ?>public/css/style.css" rel="stylesheet"/>


        <link href="<?php echo $baseurl; ?>public/css/perfect-scrollbar.css" rel="stylesheet"/>
        <link href="<?php echo $baseurl; ?>public/css/jquery.bxslider.css" rel="stylesheet"/>

        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/jquery-2.0.2.min.js"></script>
        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/App.js"></script>
        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/perfect-scrollbar.js"></script>
        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/jquery.mousewheel.js"></script>

        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/jquery.easing.1.3.js"></script>
        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/jquery.bxslider.min.js"></script>

        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/jquery.alerts.js"></script>
        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/Ui.js"></script>
        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/spin.min.js"></script>
        <link href="<?php echo $baseurl; ?>public/css/jquery.alerts.css" rel="stylesheet"/>

        <script type="text/javascript">
            App.Base_Url = '<?php echo $baseurl ?>';
            App.Base_Api = '<?php echo $baseapi ?>';
            App.Base_Upload = '<?php echo $imgurl ?>';
            var uid = '<?php echo $this->session->userdata('id_mem') == '' ? 0 : $this->session->userdata('id_mem') ?>';
            var rl = '<?php echo $this->session->userdata("role") ?>';
            var $ = jQuery.noConflict();
    
            var intro = null, background = null, WapSlider = null;
            $(function () {
                $.ajaxSetup({async: true, cache: false});

                if (localStorage.getItem("dfd5") == 1) {
                    $(".Mute").addClass("stop");
                }
                $(".Mute").on("click", function () {
                    if (localStorage.getItem("dfd5") == 1) {
                        $(".Mute").removeClass("stop");
                        localStorage.removeItem("dfd5");
                        if (background != null)
                            background.play();
                    } else {
                        $(".Mute").addClass("stop");
                        localStorage.setItem("dfd5", 1);
                        if (intro != null)
                            intro.pause();
                        if (background != null)
                            background.pause();
                    }
                    return false;
                });

                $("#sidebar_button").on("click", function () {
                    if ($("#sidebar").hasClass("show")) {
                        $("#sidebar").removeClass("show");
                    } else {
                        $("#sidebar").addClass("show");
                    }
                    return false;
                });



                /**************/
                IsMobile(function (value) {
                    if (value) {//Mobile
                        var stateAction = "";
                        $("#actionChannel").on("click", function () {
                            if ($(".MenuChannel").is(":visible")) {
                                $(".actions a.selected").removeClass("selected");
                                $(".MenuChannel").hide().empty();
                                $("#" + stateAction).addClass("selected");
                                $("#content").removeClass("hide");

                            } else {
                                stateAction = $("a.selected").attr("id");
                                $(".actions a.selected").removeClass("selected");
                                $(this).addClass("selected");
                                $(".MenuChannel").show();
                                $("#content").addClass("hide");
                                GetListMenu(uid, rl);
                            }
                            return false;
                        });

                        $('.bxslider').bxSlider({
                            pager: false});
                        /*
                         *@Menu click follow button 
                         */
                        $(document).on("click", "#sm-slideshow .btn,.MenuChannel .btn", function (e) {
                            if (rl == "guest") {
                                Toast.show({id: "gv", text: "Vui lòng đăng nhập để thao tác"});
                            } else {
                                var $this = $(this);
                                if (!$this.hasClass("active")) {
                                    $this.addClass("active");
                                    $this.parent().find(".Preload").show();
                                    if ($this.parent().find(".Preload .spinner").length == 0) {
                                        var id = $this.data("key");
                                        new Spinner(uiWaitOptions).spin(document.querySelector('#Preload_' + id + ' .Preload_inner'));
                                    }
                                    var idtvshow = $this.data("id");
                                    $.ajax({
                                        url: App.Base_Api + "follow",
                                        timeout: 10000,
                                        data: {user_id: uid, id_tvshow: idtvshow},
                                        success: function (data) {

                                            $this.removeClass("active");
                                            $this.parent().find(".Preload").hide();
                                            if (data.status == 200) {
                                                $this.removeClass("btn-follow").addClass("btn-unfollow");
                                                $("#sfollow_" + idtvshow).removeClass("btn-follow").addClass("btn-unfollow");
                                            } else if (data.status == 201) {
                                                $this.removeClass("btn-unfollow").addClass("btn-follow");
                                                $("#sfollow_" + idtvshow).removeClass("btn-unfollow").addClass("btn-follow");

                                            }
                                        }, error: function (jqXHR, textStatus) {
                                            //$this.removeClass("active");
                                            if (textStatus == "timeout") {
                                                Toast.show({text: "Kết nối quá lâu, vui lòng thử lại.", id: "gv"});
                                            } else {
                                                Toast.show({text: "Không có kết nối.", id: "gv"});
                                            }
                                        }
                                    });
                                }
                            }
                            e.preventDefault();
                            return false;
                        });

                        /*
                         *@Menu  click .image
                         */
                        $(document).on("click", ".MenuChannel li .image", function (e) {
                            var href = $(this).parents("a").attr("href");
                            var index = $(this).parents("li").index();
                            if (href == undefined || href != "" || href != null) {
                                if (WapSlider != null) {
                                    $(".actions a.selected").removeClass("selected");
                                    $(".MenuChannel").hide().empty();
                                    $("#" + stateAction).addClass("selected");
                                    $("#content").removeClass("hide");
                                    WapSlider.goToSlide(index);
                                }
                            }
                            e.preventDefault();
                            return false;
                        });
                    } else {//Desktop
                        var cH = ($(window).height() - 72) / 2;
                        $(".slider li .item").css({height: cH + "px"});
                        $('.bxslider').bxSlider({
                            pager: false
                        });
                        $(window).resize(function () {
//                            var cH = ($("#content").height() - 72) / 2;
//                            $(".slider li .item").css({height: cH + "px"});
                            location.reload();
                        });

                        $("#slideshow a, .menu a").click(function () {
                            if ($(this).data("link") != "href") {
                                new Dialog().showPoster({
                                    poster: $(this).data('poster'),
                                    channel_logo: $(this).data("channel_logo"),
                                    time: $(this).data("time")
                                });
                                return false;
                            }
                        });
                    }
                });
            });
        </script>
    </head>
    <body>
        <?php $this->load->view('template/block/sidebar'); ?>
        <?php $this->load->view('template/block/header-mobile'); ?>
        <div id="content">
            <div class="inner">
                <?php $this->load->view("template/" . ($controller ? $controller : 'index') . "/" . ($action ? $action : 'index'), ''); ?>
            </div>
            <div class="Dialog">
                <div class="Layout"></div>
                <div class="Inner"></div>
            </div>
        </div>
        <div class="MenuChannel"></div>
        <div id="ms-footer">
            <a href="#" class="Mute"></a>
            <p>Sản phẩm của <img src="<?php echo $baseurl ?>public/images/vtv-digital.png" alt=""/></p>
        </div>
        <script type="text/javascript" src="<?php echo $baseurl; ?>public/js/custom.js"></script>

        <div id="fb-root"></div>
        <script>(function (d, s, id) {
                var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id))
                    return;
                js = d.createElement(s);
                js.id = id;
                js.src = "//connect.facebook.net/vi_VN/sdk.js#xfbml=1&version=v2.0";
                fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));</script>
    </body>
</html>
